<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
        <meta content="yes" name="apple-mobile-web-app-capable">
        <meta content="black" name="apple-mobile-web-app-status-bar-style">
        <title>提交订单</title>
        <script src="__SALEMAN__/js/zepto.min.js"></script>
        <link href="__CSS__/weui.min.css" rel="stylesheet">
        <link rel="stylesheet" href="__SALEMAN__/stylesheets/index.css">
        <style type="text/css">
    .input-address-box{
      width: 100%;
      box-sizing: border-box;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      min-width: 320px;
      max-width: 640px;
      overflow: hidden;
  
      margin-bottom: 15px;
  }
    .input-address-box .adrees-txt{
        width: 100px;
        font:normal 14px/26px 'Microsoft YaHei';
        color:#000;
        float:left;
        text-align: left;
        padding-left: 15px;
        box-sizing: border-box;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
    }
    .input-address-box .adress-box{
      width: 100%;
      padding-left: 95px;
      box-sizing: border-box;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
    
    }
    .input-address-box .input-address{
      margin-bottom: 5px;
    
    }
    .input-address-box input{
      font:normal 14px/16px 'Microsoft YaHei';
      width: 90%;
      padding: 5px 10px;
      box-sizing: border-box;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      border:1px solid #ccc;
      border-radius: 3px;
      display: block;
    }
    .input-address-box .address-used{
      padding: 0 5px;
      box-sizing: border-box;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
    }
    .input-address-box .address-used p{
     font:normal 12px/16px 'Microsoft YaHei';
     padding-left: 10px;
     padding: 5px 10px;
     border-bottom:1px dashed #ccc;
    }

    </style>
    </head>
    <body>
        <div class="setelOrder">
            <header class = "all_header">
                <a class = "h_back h_back_1" href="/Home/Saleman/Saleman/orderMedicine"><img src="__SALEMAN__/images/back_icon.png" alt=""></a>
                <span class = "h_title">提交订单</span>
                <a class = "h_add" href="javascript:void(0)"></a>
            </header>
            <div class="order">
                <div class="order_adress">
                    <a class = "adress_icon" href="javascript:void(0)"><img src="__SALEMAN__/images/order_adress.png" alt=""></a>
                    <!-- <span></span> -->
                    <input class="weui-input address" style = "width:85%;"  type="text" placeholder="请输入订单地址" value = "" />
                </div>
                <div class="address-used" style="display:none;">
                <volist name="address" id="data">
               <p class="address">{$data.address}</p>
                </volist>

        </div>
                <volist name="cartList" id="cartVo">
                    <div class="order_list">
                        <div class="order_name_w">
                            <span class = "order_name">{$cartVo['drugs_name']}</span>
                            <span class = "order_del" pos_id="{$cartVo['drugs_id']}" pos_title="确定删除？">删除</span>
                        </div>
                        <div class="order_price_w">
                            <span class = "order_w">单价</span>
                            <span>¥{$cartVo['price']}</span>
                        </div>
                        <!--<div class="order_count">X{$cartVo['num']}</div>-->
                        <div class="order_count">
 <span class="js-num nu" id="{$cartVo['drugs_id']}">-</span>
  <span class="num" id="number_{$cartVo['drugs_id']}">{$cartVo['num']}</span>
  <span class="add-num nu" id="{$cartVo['drugs_id']}">+</span>
</div>

                        <div class="all_price_w">
                            <span class = "order_w">总价</span>
                            <span>¥<i class = "all_num_{$cartVo['drugs_id']}">{$cartVo['totalPrice']}</i></span>
                        </div>
                    </div>
                </volist>
                <div class="total_price_w">
                    <span class = "total_name">商品总额：</span>
                    <span>¥<i class = "total_num">{$totalPrice}</i></span>
                </div>
            </div>
            <div class="weui-footer" style="margin-bottom: 81px;">
                <p class="weui-footer__text">提交订单后，将会有县总联系您送货，谢谢您的配合</p>
            </div>
            <div class="setel_order_w">
                <div class="setel_num"><span>¥</span><span class = "setle_prices">{$totalPrice}</span>元</div>
                <div class="setel_btn" pos_title="确定提交订单？">提交订单</div>
            </div>
        </div>
        <script src = "__SALEMAN__/js/index.js"></script>
    		<script src = "__SaleManager__/js/androidback.js"></script>
    <include file="./Application/Home/View/default/Saleman/Public/popup.html"/>
    <script>
        $(function () {
        	var role = '{$myself.role_id}';
            $('.setel_btn').on('click', function () {
                var title = $(this).attr('pos_title');
                $('.confir_content').html(title);
                $('.ok-btn').attr('pos_op', 'submit');
                $("#iosDialog1").show(200);
            });

            $('.ok-btn').on('click', function () {
                //删除药品
                var op = $(this).attr('pos_op');
                if (op == 'delete') {
                    var drugs_id = $(this).attr('pos_id');
                    $.ajax({
                        url: "/Home/Saleman/Saleman/setelOrder/op/" + op,
                        type: 'post',
                        data: {drugs_id: drugs_id},
                        dataType: "json",
                        success: function (result) {
                            $("#iosDialog1").hide(200);
                            $('#iosDialog2').find('.sure-info').html(result['msg']);
                            $('#iosDialog2').show(200);
                        }
                    });
                } else if (op == 'submit') {
                    //提交订单
                    var address = $('.address').val();
                    if (address.length <= 0) {
                        $("#iosDialog1").hide(200);
                        $('#iosDialog2').find('.sure-info').html('请填写订单地址');
                        $('#iosDialog2').find('.sure-btn').attr('pos_url', '');
                        $('#iosDialog2').show(200);
                        return;
                    }
                    $.ajax({
                        url: "/Home/Saleman/Saleman/setelOrder/op/" + op,
                        type: 'post',
                        data: {address: address},
                        dataType: "json",
                        success: function (result) {

                            $("#iosDialog1").hide(200);
                            $('#iosDialog2').find('.sure-info').html(result['msg']);
                            
                           $('#iosDialog2').show(200);
                            
                            $(".weui-dialog__btn_primary").click(function(){
                            	
                             window.location.href=backUrl(role,'index');

                            })
                        }
                    });
                } else {

                }

            });

        });
                            function backUrl(roleId,url){
                    			switch(parseInt(roleId)){
                    			case 0:
                    				url= "/Home/SaleManager/Head/"+url; //总部
                    				break;	
                    			case 1:
                    				url= "/Home/SaleManager/Salemanager/"+url; //大区经理
                    				break;
                    			case 2:
                    				url= "/Home/SaleManager/Province/"+url;//省总
                    				break;
                    			case 3:
                    				url= "/Home/SaleManager/City/"+url;//地总
                    				break;
                    			case 4:
                    				url= "/Home/SaleManager/County/"+url;//县总
                    				break;
                    			case 6:
                    				url= "/Home/SaleManager/Saledepartment/"+url;//销售部
                    				break;
                    			case 7:
                    				url= "/Home/SaleManager/Career/"+url;//事业部
                    				break;	
                    			default:url= "/Home/Saleman/Saleman/"+url;//业务员
                    			}
                    			return url;
                    		}
                            $(".nu").click(function(){
                                  var flag = $(this).text();
                                  var drugs_id = $(this).attr("id");
                                  var type="";
                                  var that = $(this);
                                  if(flag=="+")
                                  {
                                        type="add";
                                  }else{
                                        type="jian";
                                  }
                                  var number = $("#number_"+drugs_id).text();
                                  if(parseInt(number)==1 && type=="jian")
                                  {
                                      return;
                                  }
                                  $.ajax({
                                      type:"POST",
                                      url:"/Home/Saleman/Saleman/number",
                                      data: {type:type,number:number,drugs_id:drugs_id},
                                      dataType: "json",
                                      success:function(msg)
                                      {
                                          if(msg.code==1)
                                          {
                                            $("#number_"+msg.result.drugs_id).text(msg.result.number);
                                            var price = msg.result.price;
                                            price = parseFloat(price);
                                            var total_price = $(".setle_prices").text();

                                            total_price = parseInt(total_price);
                                            var number = msg.result.number;
                                            number = parseInt(number);
                                            $(".all_num_"+drugs_id).text(number*price);
                                            if(msg.type=="add")
                                            {
                                                 
                                                 
                                                  total_price = total_price+price;
                                            }else if(msg.type=="jian")
                                            {
                                                  total_price = total_price-price;
                                            }
                                            $(".total_num").text(total_price);
                                            $(".setle_prices").text(total_price);
                                          }
                                      }
                                  })

                            })
                            $(".address").focus(function(){

                      $(".address-used").show();
                     
                      $(".address").click(function(){
                          var address = $(this).text();
                          $(".address").val(address);
                      })
        
       })
    </script>
</body>
</html>